import React, {
  useEffect,
  useRef,
} from 'react'

/**
 * @description 当前组件是否已卸载
 */
export const useUnmountedRef = (): React.MutableRefObject<boolean> => {
  const unmountedRef = useRef(false)
  useEffect(() => {
    unmountedRef.current = false
    return () => {
      unmountedRef.current = true
    }
  }, [])
  return unmountedRef
}
